package com.yyfax.pay.order.model.vo;

import java.util.List;

import org.apache.commons.lang3.StringUtils;

import com.yyfax.pay.common.enums.PayRspCodeEnum;
import com.yyfax.pay.common.enums.PayoutBatchStepEnum;
import com.yyfax.pay.order.model.po.PayoutBatchOrderLogPO;
import com.yyfax.pay.order.model.po.PayoutBatchOrderPO;

/**
 * 批量代付快照类
 * 
 * @author buyi
 * @date 2017-04-20 10:19:30
 * @since v1.0.0
 */
@SuppressWarnings("serial")
public class PayoutBatchOrderVO extends PayoutBatchOrderPO {
	/** 订单结果 */
	private Integer resultCode;
	/** 订单结果描述 */
	private String resultMsg;

	/** 订单是否已经关闭 */
	private boolean isClose;

	private List<PayoutOrderVO> payoutOrderVOs;

	private List<PayoutBatchOrderLogPO> payoutBatchOrderLogPOs;

	public Integer getResultCode() {
		return resultCode;
	}

	public void setResultCode(Integer resultCode) {
		this.resultCode = resultCode;
	}

	public String getResultMsg() {
		return resultMsg;
	}

	public void setResultMsg(String resultMsg) {
		this.resultMsg = resultMsg;
	}

	public boolean isClose() {
		return isClose;
	}

	public void setClose(boolean isClose) {
		this.isClose = isClose;
	}

	public List<PayoutOrderVO> getPayoutOrderVOs() {
		return payoutOrderVOs;
	}

	public void setPayoutOrderVOs(List<PayoutOrderVO> payoutOrderVOs) {
		this.payoutOrderVOs = payoutOrderVOs;
	}

	public List<PayoutBatchOrderLogPO> getPayoutBatchOrderLogPOs() {
		return payoutBatchOrderLogPOs;
	}

	public void setPayoutBatchOrderLogPOs(List<PayoutBatchOrderLogPO> payoutBatchOrderLogPOs) {
		this.payoutBatchOrderLogPOs = payoutBatchOrderLogPOs;
	}

	public PayoutOrderVO getPayoutOrderVO(String userId) {
		if (payoutOrderVOs == null || payoutOrderVOs.isEmpty()) {
			return null;
		}

		for (PayoutOrderVO vo : payoutOrderVOs) {
			if (StringUtils.equals(vo.getPayoutOrderPO().getUserId(), userId)) {
				return vo;
			}
		}

		return null;
	}

	/**
	 * 查询对应步骤的成功记录
	 * 
	 * @author jiangmy
	 * @date 2017-04-18 11:44:03
	 * @since v1.0.0
	 * @param step
	 * @return
	 */
	public PayoutBatchOrderLogPO getStep(PayoutBatchStepEnum step) {
		if (payoutBatchOrderLogPOs == null || payoutBatchOrderLogPOs.isEmpty()) {
			return null;
		}
		for (PayoutBatchOrderLogPO po : payoutBatchOrderLogPOs) {
			if (step.isValue(po.getStep()) && PayRspCodeEnum.SUCCESS.isValue(po.getResultCode())) {
				return po;
			}
		}
		return null;
	}

}
